#pragma once

#include "ukui-window-management.h"

#include "ukuiwindow.h"

#include <QLoggingCategory>
#include <QThread>
#include <qthread.h>

Q_DECLARE_LOGGING_CATEGORY(UKUIWAYLANDPROP)

namespace ukuiwaylandclient
{

class ukui_window_management_t;

class UkuiWindowManager : public QThread
{
    Q_OBJECT
public:
    enum class WindowManagementProtocol {
        UkuiWindowManagement,
        PlasmaWindowManagement,
    };

    explicit UkuiWindowManager();
    ~UkuiWindowManager();

    UkuiWindow *findWindowOnPosition(const QPoint &position) const;

signals:
    void failed();
    void finished(QString uuid);

    void windowAdded(UkuiWindow *window);
    void windowRemoved(UkuiWindow *window);

protected:
    void run() override;

private:
    bool connectToWayland();
    void disconnectFromWayland();

    bool m_stop = false;

    wl_display_t *m_display = nullptr;
    wl_registry_t *m_registry = nullptr;

    ukui_window_management_t *m_ukuiWindowManagement = nullptr;

    QList<UkuiWindow *> m_windows;
    QList<UkuiWindow *> m_stackingOrderWindows;
};

}; // namespace ukuiwaylandclient
